package guavaTest.collections;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.*;
import com.google.common.graph.ElementOrder;
import com.google.common.graph.ImmutableGraph;
import com.google.common.graph.MutableValueGraph;
import com.google.common.graph.ValueGraphBuilder;
import sun.rmi.runtime.Log;

import java.lang.reflect.Parameter;
import java.util.HashMap;
import java.util.Hashtable;

/**
 * 集合练习
 */
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
//        main.immutableCollectionTest();
//        main.multisetTest();
//        main.bitMapTest();
//        main.TableTest();
//        main.graphTest();
    }

    //不可变集合 创建之后不可以改变的集合
    public void immutableCollectionTest(){
        ImmutableList<String> immutableList = ImmutableList.of("1","2","5","8","1");
        System.out.println("immutableList:"+immutableList);
        ImmutableSet<String> immutableSet = ImmutableSet.of("1","2","5","8","1");
        System.out.println("immutableSet:"+immutableSet);
    }
    //一个键映射到多个值
    public void multisetTest(){
        Multimap<String,String> map = HashMultimap.create();
        map.put("a","1");
        map.put("a","2");
        map.put("a","3");
        map.put("a","1");
        System.out.println(map);
    }

    //bitMap可以通过key查value 也可以通过value查key。但是key和value不重复
    public void bitMapTest(){
        BiMap<String,String> weekNameMap = HashBiMap.create();
        weekNameMap.put("星期一","Monday");
        weekNameMap.put("星期二","Tuesday");
        weekNameMap.put("星期三","Wednesday");
        weekNameMap.put("星期四","Thursday");
        weekNameMap.put("星期五","Friday");
        weekNameMap.put("星期六","Saturday");
        weekNameMap.put("星期日","Sunday");
        System.out.println("星期日的英文名是" + weekNameMap.get("星期日"));
        System.out.println("Sunday的中文是" + weekNameMap.inverse().get("Sunday"));
    }
    //Table 就像表格一样 可以根据 行和列进行值得查找
    public void TableTest(){
        Table<String,String,Integer> table = HashBasedTable.create();
        table.put("zhu","java",1);
        table.put("zhu","c",6);
        table.put("chen","java",4);
        table.put("chen","c",2);
        System.out.println(table.column("java"));
        System.out.println(table);

    }

    //graph测试 图提供node节点，并且提供节点到节点的距离连线 ，适合红黑树，二叉树
    public void graphTest(){
        MutableValueGraph<String, Integer> graph = ValueGraphBuilder.directed()
                .nodeOrder(ElementOrder.insertion())
                .expectedNodeCount(10)
                .build();

        graph.putEdgeValue("V1", "V2", 6);
        graph.putEdgeValue("V1", "V3", 4);
        graph.putEdgeValue("V1", "V4", 5);
        graph.putEdgeValue("V2", "V5", 1);
        graph.putEdgeValue("V3", "V5", 1);
        graph.putEdgeValue("V4", "V6", 2);
        graph.putEdgeValue("V5", "V7", 9);
        graph.putEdgeValue("V5", "V8", 7);
        graph.putEdgeValue("V6", "V8", 4);
        graph.putEdgeValue("V7", "V9", 2);
        graph.putEdgeValue("V8", "V9", 4);
        System.out.println("graph: " + graph);

    }




}
